package config

import (
	"gopkg.in/ini.v1"
	"os"
	"fmt"
)
var (
	Port string
	Kubeconf string
	DBHost string
	DBPort string
	DBName string
	DBuser string
	DBpasswd string
	LogMod bool

)

func GetConfig()  {
	cfg, err := ini.Load("./config/config.ini")
	if err != nil {
		fmt.Printf("Fail to read file: %v", err)
		os.Exit(1)
	}
	// 典型读取操作，默认分区可以使用空字符串表示
	Port = cfg.Section("default").Key("port").String()

	if len(Port) > 0{
		if Port[0] != ':'{
			Port = ":" + Port
		}
	}else {
		Port = ":8001"
	}

	Kubeconf = cfg.Section("k8s").Key("kubeconf").String()

	DBHost = cfg.Section("mysql").Key("host").String()
	DBPort = cfg.Section("mysql").Key("port").String()

	DBName = cfg.Section("mysql").Key("dbname").String()
	DBuser = cfg.Section("mysql").Key("dbuser").String()
	DBpasswd = cfg.Section("mysql").Key("dbpassword").String()
	LogMod,err = cfg.Section("mysql").Key("LogMod").Bool()
	if err != nil {
		LogMod = false
	}

}

